package testJdk.base.param;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 方法参数的特性
 */
public class TestParam {
    //给静态方法使用的日志
    private static final Logger logger = LoggerFactory.getLogger(TestParam.class);

    /**
     * 不定长入参
     */
    @Test
    public void test01() {
        logger.info(pickMax(5).toString());
        logger.info(pickMax(5, 8, 2, 4, 5).toString());
        logger.info(pickMax(new int[]{4, 10, 6, 5}).toString());
        logger.info(pickMax().toString());
    }

    public static Integer pickMax(int... datas) {
        //避免0个参数的情况
        if (datas.length == 0) return -1;
        //遍历取最大值
        int result = 0;
        for (int a : datas) {
            if (result < a) result = a;
        }
        //返回最大值
        return result;
    }
}
